﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using RecruitmentSystem.Business;
using RecruitmentSystem.Common;

public partial class SchoolRegister : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnComplete_Click(object sender, ImageClickEventArgs e)
    {
        if (txtUserName.Text.Trim() == "" || txtPassword.Text.Trim() == "" ||
            txtAddress.Text.Trim() == "" || txtContactPerson.Text.Trim() == "" ||
            txtCreateDate.Value.Trim() == "" || txtEmail.Text.Trim() == "" ||
            txt_SchoolMemo.Text.Trim() == "" || txt_SchoolName.Text.Trim() == "" || txtTelephone.Text.Trim() == "" ||
            txtZipCode.Text.Trim() == "" || txtQuestion.Text.Trim() == "" || txtAnswer.Text.Trim() == "")
        {
            Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "emptywarning", "<script type='text/javascript'>alert('请确认带*号信息全部填写！');</script>");
            return;
        }
        else
        {
            AccountManager am = new AccountManager();
            if (!am.CheckUserId(txtUserName.Text, UserType.SchoolUser))
            {
                SchoolUser su = new SchoolUser();
                su.Address = txtAddress.Text;
                su.Contactor = txtContactPerson.Text;
                su.Description = txt_SchoolMemo.Text;
                su.SchoolType = ddlSchoolProperity.Items[ddlSchoolProperity.SelectedIndex].Text;
                su.FaxNumber = txtFax.Text;
                su.Homepage = txtWebHome.Text;
                su.MailAddress = txtEmail.Text;
                su.Name = txt_SchoolName.Text;
                su.Password = txtPassword.Text;
                su.PostCode = txtZipCode.Text;
                su.Province = ddlprovince.Items[ddlprovince.SelectedIndex].Text;
                su.District = this.CityValue.Value;
                su.Question = txtQuestion.Text;
                su.Answer = txtAnswer.Text;
                
                //eu.Code = txtCardNumber.Text;
                //eu.CreateTime = Convert.ToDateTime(txtCreateDate.Value);
                su.Size = ddlstudents.Items[ddlstudents.SelectedIndex].Text;
                su.TelephoneNumber = txtTelephone.Text;
                su.Username = txtUserName.Text;
                if (am.CreateUser(su))
                {
                    CommonUtility.SetLoginCookie(txtUserName.Text, UserType.SchoolUser.ToString());
                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "added", "<script type='text/javascript'>;document.location.href='SchoolRegistered.aspx?eid=" + txt_SchoolName.Text + "';</script>");
                    return;
                }
                else
                {
                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "failed", "<script type='text/javascript'>alert('学校注册未成功！');</script>");
                    return;
                }
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "failed", "<script type='text/javascript'>alert('用户名已经被其他用户使用，请您更换用户名再注册！');</script>");
                return;
            }
        }
    }

}
